/*  BlogBotArchive.java Version 101 - 3rd April 2008
 *  BlogBotArchive.java fills a buffer full of XML for logging purpose. Reading it back is a task for you :-)
 *  See Versions for program version number
 *  Copyright (C) 2008  Andy Broomfield andy@newmediathinking.com
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
*/
package net.blogbotplatform.blogbot;

//import java.util.*;

public class BlogBotArchive {
	
	long bufferStartTime;
	
	boolean arcRunning = true;
	String arcBuffer = "";
	
	String fileName;

	BlogBotArchive() {
		startArcBuffer();
	}

	
	void writeArc(String filePath) { 
		// write archive to the arc file		
		closeArcBuffer();
		
		System.out.println("writing Archive: " + fileName);
		Utils.writeTextFile(arcBuffer, fileName, filePath);
	
		startArcBuffer();
	}

	void startArcBuffer() {
		System.out.println("starting Archive Buffer.");
		Utils.setTimeStamp();
		bufferStartTime = System.currentTimeMillis();
		
		int s = Utils.second;
		int mi = Utils.minute;
		int h = Utils.hour;
		int d = Utils.day;
		int m = Utils.month;
		int y = Utils.year;

		fileName = "arc" + "-" + y + "-" + m + "-" + d + "--" + h + "-" + mi + "-" + s + ".txt";

		arcBuffer = "Archive for Blog Bot.";
		arcBuffer += "Started at " + d + "/" + m + "/" + y + " - " + h + ":" +  mi + "." + s + "\n\n";

		arcRunning = true;
	}

	void closeArcBuffer() {
		arcRunning = false;
		arcBuffer += "\nArchive Ends.\n";
	}

	void fillArc(String blogText) {
		if (arcRunning) {
			//println("protocol read\n");
			arcBuffer += blogText + "\n";
		}
	}

}
